#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<list>
#include<cstdlib>
#include<cmath>
#include<sstream>
#include<numeric>
#include<cstdio>
#include<cstring>
#include<stack>
using namespace std;
typedef long long LL;
int dp[26][26];
char b[26];
int main(){
	int n;
	while(scanf("%d",&n)!=EOF){
		memset(dp,0,sizeof(dp));
		for(int i=0;i<n;i++){
			scanf("%s",b);
			int m=strlen(b);
			int x=b[0]-'a',y=b[m-1]-'a';
			for(int j=0;j<26;j++)if(dp[j][x])dp[j][y]=max(dp[j][y],dp[j][x]+m);
			dp[x][y]=max(dp[x][y],m);
			}
		int ans=0;
		for(int i=0;i<26;i++)ans=max(ans,dp[i][i]);
		cout<<ans<<endl;
		}
    return 0;
    }
/*
3
abc
ca
cba

4
vvp
vvp
dam
vvp

3
ab
c
def
*/
